VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CircleSprite"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
' ************************************************
' Moving circle sprite.
' ************************************************
Option Explicit

Dim R As Integer        ' Radius.
Dim Cx As Integer       ' Position of center.
Dim Cy As Integer
Dim Vx As Integer       ' Velocity.
Dim Vy As Integer
Dim Clr As Long         ' Color.
' ************************************************
' Draw the circle on the indicated picture box.
' ************************************************
Public Sub DrawSprite(pic As PictureBox)
    pic.FillColor = Clr
    pic.Circle (Cx, Cy), R, Clr
End Sub

' ************************************************
' Initialize the circle.
' ************************************************
Public Sub InitializeSprite(radius As Integer, x As Integer, y As Integer, dx As Integer, dy As Integer, c As Long)
    R = radius
    Cx = x
    Cy = y
    Vx = dx
    Vy = dy
    Clr = c
End Sub


' ************************************************
' Add the velocity components to the sprite's
' position components.
' ************************************************
Public Sub MoveSprite(xmax As Integer, ymax As Integer)
    Cx = Cx + Vx
    Cy = Cy + Vy
    
    ' Keep the circle within the drawing area.
    If Cx < 0 Then
        Cx = -Cx
        Vx = -Vx
    ElseIf Cx > xmax Then
        Cx = 2 * xmax - Cx
        Vx = -Vx
    End If
    If Cy < 0 Then
        Cy = -Cy
        Vy = -Vy
    ElseIf Cy > ymax Then
        Cy = 2 * ymax - Cy
        Vy = -Vy
    End If
End Sub


